I'm tired of constantly refreshing and verifying that I am human. So I decided to build a local ChatGPT client. I had read about Pynecone, a Python full-stack web app development framework, a while ago and had always wanted to try it.
I mainly followed this tutorial 使用 Cloudflare Workers 解决 OpenAI 和 ChatGPT 的 API 无法访问的问题 · noobnooc/noobnooc · Discussion #9 and bought a 99 cents domain from 99 Cent Domain Name Registration | $1 Coupons - Namecheap. To add this domain to Cloudflare I just followed the instructions on the website. Later I found this guide How to set up DNS records for your domain in Cloudflare account - Hosting - Namecheap.com. The only tricky part for me was setting up the nameservers because I had never done that before. After that, I waited for about 15 minutes and the site became active.
My expectation was that I could finish the simple client in 1 or 2 hours. But it actually took much longer.
1.Python version
I declared a class Diaglog to store role and content information. For each session, I have a dialogs variable with an array of Dialog objects. Python always gives me an error when I try to access dialog.role
or dialog.content
. I tried to type annotate the dialogs variable with list[Dialog]
. A different error. After several fruitless google searches, I suddenly realized that type hinting has changed since Python 3.10. My environment was Python 3.8. So I created a 3.11 environment and the error disappeared.
2.Async?
Pynecone's button component has an is_loading
field which is perfect for signaling the user "Your input has been sent, please wait before an answer is returned". However, when I tried to change the loading state by changing the boolean variable linked to is_loading
, it doesn't work. I think it has something to do with blocking, sync, async? The fix is quite simple. Instead of putting everything in one function, have separate functions and chain them together.
pc.button(
"Send",
bg="lightblue",
color="black",
is_loading=State.is_loading,
on_click=[State.toggle_loading, State.send_message, State.toggle_loading, State.clear_input_text],
),
I like Pynecone a lot but I need to read the document closely before I build anything serious with it.
cocktailpeanut/dalai: The simplest way to run LLaMA on your local machine
Noam Chomsky: The False Promise of ChatGPT
💌Subscribe and/or 📧Email